package com.onenine.app.adapter;

import android.app.Activity;
import android.content.Context;
import android.widget.ImageView;

import com.onenine.app.activity.BrowserImageActivity;
import com.onenine.app.utils.CHelper;
import com.onenine.app.utils.GlideUtils;
import com.onenine.app.view.nineimage.NineGridImageView;
import com.onenine.app.view.nineimage.NineGridImageViewAdapter;
import com.onenine.common.util.SizeUtils;

import java.util.List;

/**
 * 多图适配器
 */
public class MultiImageAdapter extends NineGridImageViewAdapter<String> {

    private int radius;
    private NineGridImageView mMultiImageView;
    private OnItemImageClickListener mListener;

    public interface OnItemImageClickListener {
        void onItemClick(Context context, NineGridImageView multiImageView, ImageView imageView);
    }

    public MultiImageAdapter() {
        radius = SizeUtils.dp2px(5);
    }

    public MultiImageAdapter(NineGridImageView multiImageView, OnItemImageClickListener listener) {
        radius = SizeUtils.dp2px(5);
        mMultiImageView = multiImageView;
        mListener = listener;
    }

    @Override
    protected void onDisplayImage(Context context, ImageView imageView, String imageUrl) {
        GlideUtils.loadRoundImage(context, imageView, CHelper.getOssThumbImageUrl(imageUrl, imageView.getWidth()), radius);
    }

    @Override
    protected void onItemImageClick(Context context, ImageView imageView, int index, List<String> imageUrl) {
        BrowserImageActivity.launchActivity((Activity) context, imageView, imageUrl, index);
        if (mListener != null) {
            mListener.onItemClick(context, mMultiImageView, imageView);
        }
    }

}
